package com.pfzy.ui.view.strokeText;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class StrokeTextView2 extends androidx.appcompat.widget.AppCompatTextView {
    private int mStrokeColor;
    private float mStrokewidth;

    public StrokeTextView2(Context context) {
        super(context);
        init();
    }

    public StrokeTextView2(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public StrokeTextView2(Context context, AttributeSet attrs, int defstyleAttr) {
        super(context, attrs, defstyleAttr);
        init();
    }

    private void init(){
//        mStrokeColor = Color.BLACK; // 描边额色，飘为黑色
        mStrokeColor = Color.WHITE; // 描边额色，飘为黑色
        mStrokewidth = 4.0f;// 描边密度，就试为4dp
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 绘制描边救果
        getPaint().setStyle(Paint.Style.STROKE);
        getPaint().setStrokeWidth(mStrokewidth);
        setTextColor(mStrokeColor);
        super.onDraw(canvas);

        // 绘制文字
        getPaint().setStyle(Paint.Style.FILL);
//        setTextColor(Color.WHITE);
        setTextColor(Color.BLACK);
        super.onDraw(canvas);
    }

    public void setStrokeColor(int color){
        mStrokeColor = color;
        invalidate();
    }
    public void setStrokeWidth(float width){
        mStrokewidth = width;
        invalidate();
    }
}
